<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left">
      <router-link to="./form/">
        <el-button
          type="primary"
          icon="el-icon-plus"
          style="margin-left:0px"
        >添加</el-button>
      </router-link>
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
        <el-table-column align="center" prop="id" label="序号" width="70" :fixed="isMobile()?'left':undefined"/>
        <el-table-column align="center" prop="account" label="用户名" />
        <el-table-column align="center" prop="nickname" label="昵称" width="250" />
        <el-table-column align="center" prop="status" label="等级" width="80">
          <template slot-scope="scope">
            <el-tag
            >{{ level[scope.row.level_id-1]}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="region_level_str" label="类型" width="100" />
        <el-table-column align="center" prop="city_name" label="区域" width="200" />

        <el-table-column align="center" prop="status" label="是否启用" width="80">
          <template slot-scope="scope">
            <el-button
              :type="scope.row.status === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id,'status' ,scope.row.status)"
            >{{ scope.row.status === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="remark" label="备注" width="180" />
        
        <el-table-column align="center" prop="create_time" label="申请日期" width="180" />
        <el-table-column align="center" prop="apply_status_str" label="审核" width="100" />
        <el-table-column
          align="center"
          prop="telephone"
          :fixed="isMobile()?undefined:'right'"
          width="280"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button
              size="small"
              type="success"
              v-if="scope.row.apply_status==1"
              @click="order_fun(scope.row.region_id)"
            >订单</el-button>
            <el-button
              size="small"
              type="warning"
              v-if="scope.row.apply_status==1"
              @click="commission_fun(scope.row.user_id)"
            >分佣</el-button>

            <router-link :to="'./form/' + scope.row.id">
              <el-button size="small" type="primary" icon="el-icon-edit" />
            </router-link>
            <el-button
              size="small"
              type="danger"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            />
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <drawer title="订单记录" :isShow="order_visible"  @update:isShow="order_visible=false" width=".8">
       <orderList v-if="order_visible" model="admin" :region_id="region_id"/>
    </drawer>
    <drawer title="分佣记录" :isShow="commission_visible"  @update:isShow="commission_visible=false" width=".8">
      <commission-log v-if="commission_visible" :user_id="user_id"/>
    </drawer>
  </div>
</template>

<script>
import orderList from '@/components/orderlist/orderList'
import commissionLog from '@/components/orderlist/commissionLog'
import control from '@/components/control/control'
export default {
  name:'agent_index',
  components: { control ,orderList,commissionLog},
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入用户名', field: 'title', val: '' },
        {
          type: 'select',
          placeholder: '请选择等级',
          field: 'region_level',
          val: '',
          options: [
            { value: '0', label: '全部' },
            { value: '1', label: '省级' },
            { value: '2', label: '市级' },
            { value: '3', label: '区级' },
          ]
        },
      ],
      dateTime: '',
      user_id: '',
      region_id: 0,
      value: '',
      searchWhere: {
        title: ''
      },
      order_visible:false,
      commission_visible:false,
      tableData: [],
      level: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  activated(){
    if(this.$getUpdate()){
      this.onSearch()
    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    order_fun(region_id){
      this.region_id=region_id
      this.order_visible=true
    },
    commission_fun(user_id){
      this.user_id=user_id
      this.commission_visible=true
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/admin/RegionAgent/index', form, 'POST').then(e => {
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.level = e.level
        this.total = e.list.total
        this.current_page = e.list.current_page
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 修改启用状态
    change_status(id, field, val) {
      this.update(id, val, field, 'RegionAgent').then(e => {
        e ? this.onSearch() : ''
      })
    },
    // 删除
    onDel(id) {
      this.$msg_confirm().then(e => {
        if (e) {
          this.get('/admin/RegionAgent/del?id=' + id, this.form, 'POST').then(e => {
            this.onSearch()
          })
        }
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
